{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ea10719f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: flask in c:\\users\\pc\\anaconda3\\lib\\site-packages (1.1.2)\n",
      "Requirement already satisfied: itsdangerous>=0.24 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from flask) (1.1.0)\n",
      "Requirement already satisfied: click>=5.1 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from flask) (7.1.2)\n",
      "Requirement already satisfied: Jinja2>=2.10.1 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from flask) (2.11.3)\n",
      "Requirement already satisfied: Werkzeug>=0.15 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from flask) (1.0.1)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from Jinja2>=2.10.1->flask) (1.1.1)\n"
     ]
    }
   ],
   "source": [
    "!pip install flask"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fd33b83",
   "metadata": {},
   "source": [
    "# 1. web最小应用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "edfc3c3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "   WARNING: This is a development server. Do not use it in a production deployment.\n",
      "   Use a production WSGI server instead.\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:45] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:45] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:45] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:45] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:46] \"\u001b[37mGET /colorapp HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:46] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:46] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:46] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:55] \"\u001b[37mPOST /results HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:55] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:55] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:28:55] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#8d0202\n",
      "#6edddb\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [27/Dec/2023 11:29:08] \"\u001b[37mPOST /results HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:08] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:08] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:08] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#86db1f\n",
      "#92e3d5\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [27/Dec/2023 11:29:16] \"\u001b[37mPOST /results HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:16] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:16] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:16] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#b20a0a\n",
      "#ecb1b1\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [27/Dec/2023 11:29:28] \"\u001b[37mPOST /results HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:28] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:28] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:28] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#2570e9\n",
      "#d69494\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [27/Dec/2023 11:29:35] \"\u001b[37mPOST /results HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:35] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:35] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2023 11:29:35] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#74f00f\n",
      "#d6a9a9\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template,request\n",
    "app = Flask(__name__)\n",
    "\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template('index.html')\n",
    "\n",
    "@app.route('/introduction')\n",
    "def introduction():\n",
    "    return render_template('introduction.html')\n",
    "\n",
    "@app.route('/contact')\n",
    "def contact():\n",
    "    return render_template('contact.html')\n",
    "\n",
    "# 颜色选择应用的url地址，app.html是该地址的HTML页面文件\n",
    "@app.route('/colorapp')\n",
    "def colorapp():\n",
    "    return render_template('app.html')\n",
    "\n",
    "@app.route('/results',methods=[\"POST\"])\n",
    "def results():\n",
    "    # 等待处理用户提交的结果，接收用户提交的结果\n",
    "    print(request.form['selectcolor_up'])\n",
    "    print(request.form['selectcolor_down'])\n",
    "    return render_template('app.html',\n",
    "                           user_choose_color_up = request.form['selectcolor_up'],\n",
    "                           user_choose_color_down = request.form['selectcolor_down']\n",
    "                          )\n",
    "\n",
    "app.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12b4b2eb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9dedf154",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
